﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Core.Domain.Logistics
{
    /// <summary>
    /// Represents the Plan Note status enumeration
    /// 
    /// PlanNote object does not really store the enumeration value itself,
    /// but rather the string that each of the enumartion value mapped to.
    /// (See PlanNoteStatusString for more details).
    /// 
    /// Also, Plan Note status is not stored by itself, but rather is concatenated
    /// into a string that is then stored as PlanNote object's "Note" string property. 
    /// (See PlanNote object for more details!)
    /// </summary>
    public enum PlanNoteStatus : int
    {
        CreatePlan = 0,
        UpdatePlan = 1,
        AddPackage = 2,
        UpdatePackage = 3,
        RemovePackage = 4,
        UndoPackagePickup = 5,
        UndoPackageDelivery = 6,
    }

    public static class PlanNoteCommon
    {
        // PlanNoteStatusString list content has to sync up with the 
        // enum PlanNoteStatus
        // These string values are stored inside PlanNote database table.
        public static string[] PlanNoteStatusString = 
        {
            "Create Plan",
            "Plan Status Update",
            "Add Package",
            "Status Update",
            "Remove Package",
            "Undo Pickup",
            "Undo Delivery",
        };

        public static PlanNoteStatus StringToPlanNoteStatus(string statusString)
        {
            var numStatusStrings = PlanNoteStatusString.Count();
            if (numStatusStrings == 0)
                throw new Exception("PlanNoteStatusString array is empty");

            int idx = 0;
            for (; idx < numStatusStrings; idx++)
            {
                if (String.Equals(statusString, PlanNoteStatusString[idx], StringComparison.InvariantCulture))
                {
                    break;
                }
            }

            if( idx >= numStatusStrings )
                throw new Exception(String.Format("Unknown PlanNote Status String: {0}", statusString));

            var pnStatus = (PlanNoteStatus)idx;
            return pnStatus;
        }
    }
}
